import java.util.ArrayList;
import java.util.List;

public class DataModelPrepare {
	
	private CSVReader reader = null;
	private List<DataModel> data = null;
	private List<String> attrList = null;
	
	public DataModelPrepare(String path){
		reader = new CSVReader(path);
	}
	
	public DataModelPrepare(String path,char spliter){
		reader = new CSVReader(spliter, path);
	}
	
	public List<String> getAttrList(){
		readAttrList();
		return attrList;
	}
	
	public List<DataModel> getDataModel(){
		if(data == null){
			data = new ArrayList<DataModel>();
			readDataModels();
		}
		return data;
	}
	
	private void readAttrList(){
		System.out.println("- Reading attribute list...");
		attrList = reader.readOneRow();
		attrList.remove("y");
		System.out.println("- Done! attrList :\n\t"+attrList);
	}
	
	private void readDataModels(){
		
		List<String> row;
		while((row = reader.readOneRow())!=null){
			DataModel dm = new DataModel();
			for(int i = 0;i < row.size()-1;i++){
				dm.attrs.put(attrList.get(i), row.get(i));
			}
			dm.label = row.get(row.size()-1);
			data.add(dm);
		}
	}
}
